﻿using System;
using System.Data;
using System.Runtime.Serialization;

namespace System
{
    /// <summary>
    /// 字段属性
    /// </summary>
    [AttributeUsage(AttributeTargets.Property)]    
    [Serializable]
    public class ModelFieldAttribute : Attribute
    {
        /// <summary>
        /// 字段类型
        /// </summary>
        
        public Type Type { get; set; }
        /// <summary>
        /// 字段名称
        /// </summary>
        
        public string Name { get; set; }
        /// <summary>
        /// 字段描述
        /// </summary>
        
        public string Description { get; set; }
        /// <summary>
        /// 是否为主键
        /// </summary>
        
        public bool IsKeyField { get; set; }
        /// <summary>
        /// 是否由数据库自动生成
        /// </summary>
        
        public bool IsDbGenerated { get; set; }
        /// <summary>
        /// 字段长度
        /// </summary>
        
        public int Size { get; set; }
        /// <summary>
        /// 字段是否可为空
        /// </summary>
        
        public bool IsAllowNull { get; set; }
        /// <summary>
        /// 字段数据错误信息
        /// </summary>
        
        public string ErrorMessage { get; set; }
        /// <summary>
        /// 验证表达式
        /// </summary>
        
        public string ValidationExpression { get; set; }
        /// <summary>
        /// 自定义ID生成方法的完整名称
        /// </summary>
        
        public string IdGeneratorName { get; set; }
        /// <summary>
        /// 字段形式
        /// </summary>
        
        public FieldType FieldType { get; set; }
        /// <summary>
        /// 数据库字段类型
        /// </summary>

        
        public string DbType { get; set; }
        /// <summary>
        /// 是否记录修改日志
        /// </summary>
        
        public bool IsNeedRecordModify { get; set; }

        /// <summary>
        /// 是否唯一
        /// </summary>
        
        public bool IsUnique { get; set; }

        /// <summary>
        /// 是否为外键
        /// </summary>
        
        public bool IsForeignKey { get; set; }
    }
    /// <summary>
    /// 实体属性
    /// </summary>
    
    [Serializable]
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
    public class ModelAttribute : Attribute
    {
        /// <summary>
        /// 主键集合
        /// </summary>
        
        public string PrimaryKey { get; set; }
        /// <summary>
        /// 实体类型
        /// </summary>
        
        public ModelType ModelType { get; set; }
        /// <summary>
        /// 实体名称
        /// </summary>
        
        public string Name { get; set; }
        /// <summary>
        /// 必备条件
        /// </summary>
        
        public string Condition { get; set; }
        /// <summary>
        /// 是否记录修改日志
        /// </summary>
        
        public bool IsNeedRecordModify { get; set; }
    }
    /// <summary>
    /// 关联属性
    /// </summary>
    
    [Serializable]
    [AttributeUsage(AttributeTargets.Property)]
    public class RelationAttribute : Attribute
    {
        /// <summary>
        /// 关系名称
        /// </summary>
        
        public string Name { get; set; }
        /// <summary>
        /// 关联字段
        /// </summary>
        
        public string KeyField { get; set; }
        /// <summary>
        /// 父对象关联字段
        /// </summary>
        
        public string ParentKeyField { get; set; }
        /// <summary>
        /// 是否主动更新
        /// </summary>
        
        public bool IsInitiactiveModify { get; set; }
        /// <summary>
        /// 必备条件
        /// </summary>
        
        public string Condition { get; set; }
    }
}
